package cn.stylefeng.guns.utils;

import cn.stylefeng.guns.base.auth.jwt.JwtTokenUtil;
import cn.stylefeng.guns.base.auth.jwt.payload.JwtPayLoad;
import cn.stylefeng.guns.modular.ums.model.params.MemberParam;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;

/**
 * 〈一句话功能简述〉<br>
 * 〈MemberToken〉
 *
 * @author muconan
 * @create 2019/12/26
 * @since 1.0.0
 */
public class MemberTokenUtil {

    /**
     * 取得当前Token登录者会员的ID
     * @return
     */
    public static int getMemberId(){
        int memberId = 0;
        String str_token = HttpContextUtils.getHttpServletRequest().getHeader("token");
        if(JwtTokenUtil.checkToken(str_token)){
            JwtPayLoad jwt =  JwtTokenUtil.getJwtPayLoad(str_token);
            memberId = jwt.getUserId().intValue();
        }else if (str_token.equals("canNotPost")){
        }else{
            throw new RequestEmptyException("ToKen信息认证失败！");
        }
        return  memberId ;
    }

}